<?php
namespace Home\Service;
use Think\Think;
class YTX extends Think{
    //主帐号
    private $accountSid= '8a216da85bad7876015bb240c3f10195';

    //主帐号Token
    private $accountToken= '1ae3585d242e4fe8828945b98bc7be2f';

    //应用Id
    private $appId='8a216da85bad7876015bb240c48e019b';

    //请求地址
    private $serverIP='app.cloopen.com';

    //请求端口 
    private $serverPort='8883';

    //REST版本号
    private $softVersion='2013-12-26';

//---------------------------语言验证码-------------------------------
	function voiceVerify($verifyCode,$playTimes,$to,$displayNum,$respUrl){
	$this->appId='8a216da85bad7876015bb240c48e019b';
		// vendor("SDK.CCPRestSDK");
        // 初始化REST SDK
        $rest = new REST($this->serverIP,$this->serverPort,$this->softVersion);
        $rest->setAccount($this->accountSid,$this->accountToken);
        $rest->setAppId($this->appId);
        //返回内容
        $str='';
       
        //调用语音验证码接口
        $str.="Try to make a voiceverify,called is $to <br/>";
        $result = $rest->voiceVerify($verifyCode,$playTimes,$to,$displayNum,$respUrl);
        if($result == NULL ) {
            $str.= "result error!";
            break;
        }
        
        if($result->statusCode!=0) {
            $str.= "error code :" . $result->statusCode . "<br>";
            $str.= "error msg :" . $result->statusMsg . "<br>";
            //TODO 添加错误处理逻辑
        } else{
            $str.= "voiceverify success!<br>";
            // 获取返回信息
            $voiceVerify = $result->VoiceVerify;
            $str.= "callSid:".$voiceVerify->callSid."<br/>";
            $str.= "dateCreated:".$voiceVerify->dateCreated."<br/>";
           //TODO 添加成功处理逻辑
        } 
        return $str;
	}

//---------------------------短息验证码-------------------------------
    function sendTemplateSMS($to,$datas,$tempId){
    $this->appId='8a216da85bad7876015bb240c48e019b';
        // vendor("SDK.CCPRestSDK");
        // 初始化REST SDK
        
        $rest = new \Home\Service\REST($this->serverIP,$this->serverPort,$this->softVersion);
        $rest->setAccount($this->accountSid,$this->accountToken);
        $rest->setAppId($this->appId);
        //返回内容
    
        // 发送模板短信
        $str = '';
        $str += "Sending TemplateSMS to $to <br/>";
        $result = $rest->sendTemplateSMS($to,$datas,$tempId);
       // dump($result);
        if($result == NULL ) {
            $str += "result error!";
            return $str;
        }
        if($result->statusCode!=0) {
            $str += "error code :" . $result->statusCode . "<br>";
            $str += "error msg :" . $result->statusMsg . "<br>";
            return $str;
            //TODO 添加错误处理逻辑
        }else{
            $str += "Sendind TemplateSMS success!<br/>";
            // 获取返回信息
            $smsmessage = $result->TemplateSMS;
            $str += "dateCreated:".$smsmessage->dateCreated."<br/>";
            $str += "smsMessageSid:".$smsmessage->smsMessageSid."<br/>";
            //TODO 添加成功处理逻辑
        }
        return $str;
    }
}
?>